package main

import (
	"fmt"
	"math/rand"
)

func main() {
	// 作业一：打印九九乘法表。
	fmt.Println("作业一：")
	homeWork1()
	// 作业二：随机生成20以内的20个非0正整数，打印出来。对生成的数值，第单数个（不是索引）累加求和，
	//偶数个累乘求积
	fmt.Println("作业二：")
	homeWork2()
	// 作业三：打印100以内的斐波那契数列
	fmt.Println("作业三：")
	homeWork3()

}

func homeWork1() {
	for i := 1; i < 10; i++ {
		for j := 1; j < 10; j++ {
			if j <= i {
				fmt.Printf("%d * %d = %d\t", j, i, j*i)
			}
		}
		fmt.Println()
	}
}

func homeWork2() {
	sum := 0
	multiply := 1
	randnum := []int{}
	for i := 0; i < 20; i++ {
		num := rand.Intn(20) + 1
		randnum = append(randnum, num)
		if num%2 == 0 {
			multiply *= num
		} else {
			sum += num
		}

	}
	fmt.Printf("20个随机数:%v\n", randnum)
	fmt.Printf("奇数求和:%d\n偶数求积:%d\n", sum, multiply)

}

func homeWork3() {
	a, b := 0, 1
	for {
		fmt.Printf("%d ", a)
		c := a
		a = b
		b = c + b
		if a > 100 {
			break
		}
	}
}
